home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / timeslaving / src / controlpanel.java next >
Encoding:
Java Source  |  2000-06-23  |  4.1 KB  |  146 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import java.io.*;
  11.  
  12. import quicktime.*;
  13. import quicktime.app.time.*;
  14. import quicktime.io.*;
  15. import quicktime.std.movies.*;
  16. import quicktime.std.*;
  17. import quicktime.std.image.*;
  18. import quicktime.app.*;
  19. import quicktime.app.players.*;
  20. import quicktime.app.display.*;
  21. /**
  22.  * A simple panel of AWT objects to demonstrate how AWT can be used to control a
  23.  * QuickTime movie.
  24.  */
  25. public class ControlPanel extends Panel implements Errors, StdQTConstants {
  26. private String strx;
  27. //_________________________ CLASS METHODS
  28.     public ControlPanel (Timer ti, Frame m) {
  29.         this.t = ti;
  30.         this.f = m;
  31.         
  32.         GridBagLayout gb = new GridBagLayout();
  33.         setLayout (gb);
  34.         setFont (new Font("Helvetica", Font.BOLD, 10));
  35.  
  36.         GridBagConstraints cons = new GridBagConstraints();
  37.         cons.fill = GridBagConstraints.HORIZONTAL;
  38.         cons.gridheight = 1;        
  39.         cons.insets = new Insets (2, 2, 2, 2);        
  40.         cons.gridwidth = 2;
  41.         cons.gridy = 0;
  42.         cons.gridx = 0;
  43.         add (rateLabel, cons);
  44.         
  45.         cons.gridx = 2;
  46.         add (rateField, cons);
  47.  
  48.         cons.gridx = 4;
  49.         add (makeMovie, cons);
  50.         
  51.         cons.gridy = 1;
  52.         cons.gridx = 0;
  53.         add (scaleLabel, cons);
  54.         
  55.         cons.gridx = 2;
  56.         add (scaleField, cons);
  57.  
  58.         cons.gridx = 4;
  59.         add (periodLabel, cons);
  60.         
  61.         cons.gridx = 6;
  62.         add (periodField, cons);
  63.         
  64.         
  65.         
  66.         rateField.addActionListener (new ActionListener () {
  67.                 public void actionPerformed (ActionEvent event) {
  68.                     strx = new String (event.getActionCommand());
  69.                     t.setRate (new Float (strx).floatValue());
  70.                     
  71.                 }
  72.             });
  73.         scaleField.addActionListener (new ActionListener () {
  74.                 public void actionPerformed (ActionEvent event) {
  75.                     String str = new String (event.getActionCommand());
  76.                     try {
  77.                         t.rescheduleTickle (new Integer (str).intValue(), t.getPeriod());
  78.                     } catch (QTException e) {
  79.                         e.printStackTrace();
  80.                     }
  81.                 }
  82.             });    
  83.         periodField.addActionListener (new ActionListener () {
  84.                 public void actionPerformed (ActionEvent event) {
  85.                     String str = new String (event.getActionCommand());
  86.                     try {
  87.                         t.rescheduleTickle (t.getScale(), new Integer (str).intValue());
  88.                     } catch (QTException e) {
  89.                         e.printStackTrace();
  90.                     }
  91.                 }
  92.             });    
  93.         makeMovie.addActionListener (new ActionListener () {
  94.                 public void actionPerformed (ActionEvent event) {                        
  95.                     try {
  96.                         QTCanvas movCanv = new QTCanvas(QTCanvas.kInitialSize, 0.5f, 0.5f);
  97.                         f.add ("West", movCanv);
  98.                         File fl = QTFactory.findAbsolutePath ("jumps.mov");
  99.                         OpenMovieFile movieFile = OpenMovieFile.asRead(new QTFile(fl));
  100.                         Movie mov = Movie.fromFile (movieFile);                        
  101.                         t.getTimeBase().setMasterTimeBase(mov.getTimeBase(), null);
  102.                         MovieController mc = new MovieController (mov);
  103.                         mc.setLooping (true);
  104.                         p = new QTPlayer (mc);
  105.                         movCanv.setClient (p, true);
  106.                     } catch (Exception e) {
  107.                         e.printStackTrace();
  108.                     }
  109.                 }
  110.             });    
  111.     }
  112.  
  113.     QTPlayer p;
  114.     Frame f;
  115.     
  116.     public void setDisplay () throws QTException {
  117.         rateField.setText (Float.toString (t.getRate()));
  118.         scaleField.setText (Integer.toString (t.getScale()));
  119.         periodField.setText (Integer.toString (t.getPeriod()));
  120.     }
  121.     
  122. //_________________________ INSTANCE VARIABLES
  123.     private Label rateLabel = new Label ("Playback Rate:", Label.RIGHT);
  124.     private TextField rateField = new TextField (8);
  125.  
  126.     private Label scaleLabel = new Label ("Scale:", Label.RIGHT);
  127.     private TextField scaleField = new TextField (8);
  128.  
  129.     private Label periodLabel = new Label ("Period:", Label.RIGHT);
  130.     private TextField periodField = new TextField (8);
  131.     
  132.     private Button makeMovie = new Button ("Make Movie");
  133.     Timer t;
  134.  
  135. //_________________________ INSTANCE METHODS
  136.     /**
  137.      * @return a Dimension object which defines the minimum size
  138.      */     
  139.     public Dimension getMinimumSize() { return new Dimension (0, 80); }
  140.  
  141.     /**
  142.      * @return a Dimension object which defines the preferred size
  143.      */     
  144.     public Dimension getPreferredSize() { return getMinimumSize(); }
  145. }
  146.